// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso.objects;

import zombie.core.Rand;
import zombie.core.opengl.Shader;
import zombie.core.textures.ColorInfo;
import zombie.iso.IsoCell;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoObject;
import zombie.iso.IsoPhysicsObject;
import zombie.iso.IsoWorld;
import zombie.iso.Vector2;
import zombie.iso.sprite.IsoSpriteInstance;

public class IsoBloodDrop extends IsoPhysicsObject {
    public float tintb = 1.0F;
    public float tintg = 1.0F;
    public float tintr = 1.0F;
    public float time = 0.0F;
    float sx = 0.0F;
    float sy = 0.0F;
    float lsx = 0.0F;
    float lsy = 0.0F;
    static Vector2 temp = new Vector2();

    public IsoBloodDrop(IsoCell cell) {
        super(cell);
    }

    @Override
    public boolean Serialize() {
        return false;
    }

    @Override
    public String getObjectName() {
        return "ZombieGiblets";
    }

    @Override
    public void collideGround() {
        float float0 = this.x - (float)((int)this.x);
        float float1 = this.y - (float)((int)this.y);
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare((int)this.x, (int)this.y, (int)this.z);
        if (isoGridSquare != null) {
            IsoObject isoObject = isoGridSquare.getFloor();
            isoObject.addChild(this);
            this.setCollidable(false);
            IsoWorld.instance.CurrentCell.getRemoveList().add(this);
        }
    }

    @Override
    public void collideWall() {
        IsoGridSquare isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare((int)this.x, (int)this.y, (int)this.z);
        if (isoGridSquare != null) {
            IsoObject isoObject = null;
            if (this.isCollidedN()) {
                isoObject = isoGridSquare.getWall(true);
            } else if (this.isCollidedS()) {
                isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare((int)this.x, (int)this.y + 1, (int)this.z);
                if (isoGridSquare != null) {
                    isoObject = isoGridSquare.getWall(true);
                }
            } else if (this.isCollidedW()) {
                isoObject = isoGridSquare.getWall(false);
            } else if (this.isCollidedE()) {
                isoGridSquare = IsoWorld.instance.CurrentCell.getGridSquare((int)this.x + 1, (int)this.y, (int)this.z);
                if (isoGridSquare != null) {
                    isoObject = isoGridSquare.getWall(false);
                }
            }

            if (isoObject != null) {
                isoObject.addChild(this);
                this.setCollidable(false);
                IsoWorld.instance.CurrentCell.getRemoveList().add(this);
            }
        }
    }

    @Override
    public void update() {
        super.update();
        this.time = this.time + zombie.GameTime.instance.getMultipliedSecondsSinceLastUpdate();
        if (this.velX == 0.0F && this.velY == 0.0F && this.getZ() == (float)((int)this.getZ())) {
            this.setCollidable(false);
            IsoWorld.instance.CurrentCell.getRemoveList().add(this);
        }
    }

    @Override
    public void render(float x, float y, float z, ColorInfo info, boolean bDoAttached, boolean bWallLightingPass, Shader shader) {
        this.setTargetAlpha(0.3F);
        this.sprite.render(this, x, y, z, this.dir, this.offsetX, this.offsetY, info, true);
    }

    public IsoBloodDrop(IsoCell cell, float x, float y, float z, float xvel, float yvel) {
        super(cell);
        this.velX = xvel * 2.0F;
        this.velY = yvel * 2.0F;
        this.terminalVelocity = -0.1F;
        this.velZ = this.velZ + ((float)Rand.Next(10000) / 10000.0F - 0.5F) * 0.05F;
        float _float = (float)Rand.Next(9000) / 10000.0F;
        _float += 0.1F;
        this.velX *= _float;
        this.velY *= _float;
        this.velZ += _float * 0.05F;
        if (Rand.Next(7) == 0) {
            this.velX *= 2.0F;
            this.velY *= 2.0F;
        }

        this.velX *= 0.8F;
        this.velY *= 0.8F;
        temp.x = this.velX;
        temp.y = this.velY;
        temp.rotate(((float)Rand.Next(1000) / 1000.0F - 0.5F) * 0.07F);
        if (Rand.Next(3) == 0) {
            temp.rotate(((float)Rand.Next(1000) / 1000.0F - 0.5F) * 0.1F);
        }

        if (Rand.Next(5) == 0) {
            temp.rotate(((float)Rand.Next(1000) / 1000.0F - 0.5F) * 0.2F);
        }

        if (Rand.Next(8) == 0) {
            temp.rotate(((float)Rand.Next(1000) / 1000.0F - 0.5F) * 0.3F);
        }

        if (Rand.Next(10) == 0) {
            temp.rotate(((float)Rand.Next(1000) / 1000.0F - 0.5F) * 0.4F);
        }

        this.velX = temp.x;
        this.velY = temp.y;
        this.x = x;
        this.y = y;
        this.z = z;
        this.nx = x;
        this.ny = y;
        this.setAlpha(0.5F);
        this.def = IsoSpriteInstance.get(this.sprite);
        this.def.alpha = 0.4F;
        this.sprite.def.alpha = 0.4F;
        this.offsetX = -26.0F;
        this.offsetY = -242.0F;
        this.offsetX += 8.0F;
        this.offsetY += 9.0F;
        this.sprite.LoadFramesNoDirPageSimple("BloodSplat");
    }
}
